package model;

import java.awt.Color;
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InvalidClassException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

import javax.swing.ImageIcon;

/**
 * This class is used as an extension of Player to differentiate between humans
 * and robotic combatants.
 * 
 * @author David Shefchik
 * 
 */
public class HumanPlayer extends Player {

	/**
	 * The constructor takes no arguments, just calls the constructor of the
	 * superclass.
	 */
	// public HumanPlayer(String name, Color color, ImageIcon icon, Map map)
	public HumanPlayer(String name, Color color, ImageIcon icon) {
		super(name, color, icon);

		ObjectOutputStream oos = null; 
		ObjectInputStream ois;

		try {
			ois = new ObjectInputStream(new FileInputStream("profile.dat"));
			profile = (Profile) ois.readObject();
			System.out.println("I read");
		} catch (EOFException e) {
			profile = new Profile(name, color, icon);
			try {
				oos = new ObjectOutputStream(
						new FileOutputStream("profile.dat"));
				oos.writeObject(profile);
			} catch (FileNotFoundException fe) {
				fe.printStackTrace();
			} catch (IOException ie) {
				ie.printStackTrace();
			}
		} catch (FileNotFoundException e) {
			profile = new Profile(name, color, icon);
			try {
				oos = new ObjectOutputStream(
						new FileOutputStream("profile.dat"));
				oos.writeObject(profile);
				System.out.println("I wrote the profile on the output stream");
			} catch (FileNotFoundException fe) {
				fe.printStackTrace();
			} catch (IOException ie) {
				ie.printStackTrace();
			}
		} catch (InvalidClassException ice) {
			System.out.println("InvalidClassException");
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		
		

	}

	/**
	 * Prints the name and color of this player
	 */
	public String toString() {
		return (this.getName() + "  " + this.getColor());
	}
}
